import request from '@/utils/request'

// 获取新的商品信息
export const getNewCartGoods = (skuId) => {
  return request({
    url: `/goods/stock/${skuId}`,
    method: 'get'
  })
}

// 获取商品的specs和skus
export const getSpecsAndSkus  = (skuId) => {
  return request({
    url: `/goods/sku/${skuId}`,
    method: 'get'
  })
}

// 合并本地购物车
export const mergeCart = (cartList) => {
  return request({
    method: 'post',
    url:'/member/cart/merge',
    data:cartList
  })
}

// 获取登录后的购物车列表
export const findCart = () => {
  return request({ url:'/member/cart', method: 'get'})
}


// 加入购物车
export const insertCart = ({ skuId, count }) => {
  return request({
    method:'post',
    url: '/member/cart',
    data:{ skuId, count}
  })
}

// 删除商品（支持批量删除）
export const deleteCart  = (ids) => {
  return request({
    method:'DELETE',
    url: '/member/cart',
    data:{ids}
  })
}
//  修改购物车商品的状态和数量
export const updateCart = (goods) => {
  return request({
    method:'put',
    url: `/member/cart/${goods.skuId}`,
    data:{
      selected:goods.selected,
      count: goods.count
    }
  })
}

// 全选
export const checkAllCart = ({ selected, ids }) => {
  return request({
    url: '/member/cart/selected',
    method: 'put',
    data: { selected, ids }
  })
}
